package com.hpin.fansea.widget;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.hpin.fansea.R;
import com.hpin.fansea.adapter.ProviewAdapter;
import com.hpin.fansea.base.BaseActivity;
import com.hpin.fansea.photoview.PhotoView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.List;

/**
 * 预览图片页面
 * Created by Aaron on 15/9/14.
 */
public class PreviewPhotoActivity extends BaseActivity {

    public DisplayImageOptions options;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_photo_view);

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.icon_loading_big_default)
                .showImageForEmptyUri(R.mipmap.icon_fail_big_default)
                .showImageOnFail(R.mipmap.icon_fail_big_default)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true).cacheInMemory(true)
                .cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .displayer(new SimpleBitmapDisplayer()).build();

        int position = getIntent().getIntExtra("position", 0);

        List<String> details = (List<String>) getIntent().getSerializableExtra("picLists");

        List<PhotoView> photoviews = new ArrayList<PhotoView>();

        for (String b : details) {

            PhotoView photoView = new PhotoView(this);

            ImageLoader.getInstance().displayImage(b, photoView, options);

//            photoView.setImageBitmap(CommonUtils.getBitmapFromPath(b.mPath));
            photoviews.add(photoView);

        }

        ProviewAdapter proviewAdapter = new ProviewAdapter(photoviews, this);
        ViewPager vp_pics = (ViewPager) findViewById(R.id.vp_pics);

        vp_pics.setAdapter(proviewAdapter);
        vp_pics.setCurrentItem(position);

    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);       //统计时长
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    public void widgetClick(View v) {

    }

}
